import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { PerEduExperienceApi } from '#/api/per/eduExperience';
import type { DescriptionItemSchema } from '#/components/description';

import { h } from 'vue';

import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { formatDate, formatDateTime } from '@vben/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'startDate',
      label: '开始时间',
      component: 'DatePicker',
      componentProps: {
        showTime: false,
        format: 'YYYY-MM-DD',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'endDate',
      label: '结束时间',
      component: 'DatePicker',
      componentProps: {
        showTime: false,
        format: 'YYYY-MM-DD',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'schoolName',
      label: '学校名称',
      component: 'Input',
      componentProps: { placeholder: '请输入学校名称' },
    },
    {
      fieldName: 'collegeName',
      label: '院系名称',
      component: 'Input',
      componentProps: { placeholder: '请输入院系名称' },
    },
    {
      fieldName: 'major',
      label: '所学专业',
      component: 'Input',
      componentProps: { placeholder: '请输入所学专业' },
    },
    {
      fieldName: 'educationLevel',
      label: '学历',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.PER_EDUCATION_LEVEL),
        placeholder: '请选择学历',
      },
    },
    {
      fieldName: 'degree',
      label: '学位',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.PER_DEGREE),
        placeholder: '请选择学位',
      },
    },
    {
      fieldName: 'graduationStatus',
      label: '毕结业状态',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.PER_GRADUATION_STATUS),
        placeholder: '请选择毕结业状态',
      },
    },
    {
      fieldName: 'isFullTime',
      label: '全日制',
      component: 'RadioGroup',
      defaultValue: true,
      componentProps: {
        options: [
          { label: '是', value: true },
          { label: '否', value: false },
        ],
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'isHighest',
      label: '是否最高学历',
      component: 'RadioGroup',
      defaultValue: false,
      componentProps: {
        options: [
          { label: '是', value: true },
          { label: '否', value: false },
        ],
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'learningForm',
      label: '学习形式',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.PER_LEARNING_FORM),
        placeholder: '请输入学习形式',
      },
    },
    {
      fieldName: 'admissionMethod',
      label: '入学方式',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.PER_ADMISSION_METHOD),
        placeholder: '请输入入学方式',
      },
    },
    {
      fieldName: 'certificateNo',
      label: '学历证书编号',
      component: 'Input',
      componentProps: { placeholder: '请输入学历证书编号' },
    },
    {
      fieldName: 'degreeCertificateNo',
      label: '学位证书编号',
      component: 'Input',
      componentProps: { placeholder: '请输入学位证书编号' },
    },

    {
      component: 'ImageUpload',
      fieldName: 'attachment',
      label: '附件',
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'remarks',
      label: '备注',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: { placeholder: '请输入备注' },
    },
  ];
}

/** 详情页字段 */
export function useDetailSchema(): DescriptionItemSchema[] {
  return [
    {
      label: '人员ID，对应 per_employee.id',
      field: 'employeeId',
    },
    {
      label: '是否全日制（1：是，0：否）',
      field: 'isFullTime',
      render: (val) => formatDateTime(val, 'YYYY-MM-DD HH:mm:ss') as string,
    },
    {
      label: '学校名称',
      field: 'schoolName',
    },
    {
      label: '院系名称',
      field: 'collegeName',
    },
    {
      label: '所学专业',
      field: 'major',
    },
    {
      label: '开始时间',
      field: 'startDate',
      render: (val) => formatDate(val, 'YYYY-MM-DD') as string,
    },
    {
      label: '结束时间',
      field: 'endDate',
      render: (val) => formatDate(val, 'YYYY-MM-DD') as string,
    },
    {
      label: '毕结业状态（毕业/结业/肄业等）',
      field: 'graduationStatusName',
    },
    {
      label: '学历',
      field: 'educationLevel',
    },
    {
      label: '学位',
      field: 'degree',
    },
    {
      label: '是否最高学历（1：是，0：否）',
      field: 'isHighest',
    },
    {
      label: '学习形式（全日制/非全日制/函授/夜大等）',
      field: 'learningForm',
    },
    {
      label: '入学方式（统招/自考/成人高考等）',
      field: 'admissionMethod',
    },
    {
      label: '学历证书编号',
      field: 'certificateNo',
    },
    {
      label: '学位证书编号',
      field: 'degreeCertificateNo',
    },
    {
      label: '是否有效（1：有效，0：无效）',
      field: 'isValid',
    },
    {
      label: '附件（证明材料URL或文件路径）',
      field: 'attachment',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '备注',
      field: 'remarks',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'schoolName',
      label: '学校名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入学校名称',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<PerEduExperienceApi.EduExperience>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
      visible: false,
    },
    {
      field: 'employeeId',
      title: '人员ID，对应 per_employee.id',
      minWidth: 120,
    },
    {
      field: 'isFullTime',
      title: '是否全日制（1：是，0：否）',
      minWidth: 120,
    },
    {
      field: 'schoolName',
      title: '学校名称',
      minWidth: 120,
    },
    {
      field: 'collegeName',
      title: '院系名称',
      minWidth: 120,
    },
    {
      field: 'major',
      title: '所学专业',
      minWidth: 120,
    },
    {
      field: 'startDate',
      title: '开始时间',
      minWidth: 120,
    },
    {
      field: 'endDate',
      title: '结束时间',
      minWidth: 120,
    },
    {
      field: 'graduationStatus',
      title: '毕结业状态（毕业/结业/肄业等）',
      minWidth: 120,
    },
    {
      field: 'educationLevel',
      title: '学历',
      minWidth: 120,
    },
    {
      field: 'degree',
      title: '学位',
      minWidth: 120,
    },
    {
      field: 'isHighest',
      title: '是否最高学历（1：是，0：否）',
      minWidth: 120,
    },
    {
      field: 'learningForm',
      title: '学习形式（全日制/非全日制/函授/夜大等）',
      minWidth: 120,
    },
    {
      field: 'admissionMethod',
      title: '入学方式（统招/自考/成人高考等）',
      minWidth: 120,
    },
    {
      field: 'certificateNo',
      title: '学历证书编号',
      minWidth: 120,
    },
    {
      field: 'degreeCertificateNo',
      title: '学位证书编号',
      minWidth: 120,
    },
    {
      field: 'isValid',
      title: '是否有效（1：有效，0：无效）',
      minWidth: 120,
    },
    {
      field: 'attachment',
      title: '附件（证明材料URL或文件路径）',
      minWidth: 120,
    },
    {
      field: 'remarks',
      title: '备注',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
    },
    {
      field: 'actions',
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
